package cn.itcast.mq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description AmqpConfig
 * @Author luohai
 * @Date 2024-11-13
 */
@Configuration
public class AmqpConfig {

    /**
     * 创建简单模型消息队列
     * @return
     */
    @Bean
    public Queue queue(){
        return new Queue("simple.queue");
    }

    /**
     * 创建简工作队列模型消息队列
     * @return
     */
    @Bean
    public Queue queue1(){
        return new Queue("work.queue");
    }

    /**
     * 创建fanout广播模型消息队列
     * @return
     */
    @Bean
    public Queue fanoutQueue1(){
        return new Queue("fanout.queue1");
    }

    @Bean
    public Queue fanoutQueue2(){
        return new Queue("fanout.queue2");
    }

    /**
     * 创建fanout广播模型交换机
     * @return
     */
    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange("fanout.exchange");
    }

    /**
     * fanout广播模型队列绑定交换机
     * @return
     */
    @Bean
    public Binding binding1(Queue fanoutQueue1,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(fanoutQueue1).to(fanoutExchange);
    }

    @Bean
    public Binding binding2(Queue fanoutQueue2,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(fanoutQueue2).to(fanoutExchange);
    }
}
